package com.zhudao.crawler.service;

import com.alibaba.fastjson.JSON;
import com.zhudao.crawler.util.PinyinUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PinyinService {
    @Autowired
    @Qualifier("primaryJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    public void aa() {
        List<Map<String, Object>> map = jdbcTemplate.queryForList("SELECT *  from city_business where  city_id=1");
        System.out.println(JSON.toJSON(map));
        for (Map<String, Object> map1 : map) {
            String name = (String) map1.get("name");
            int id = (int) map1.get("id");
            String pinyin = PinyinUtils.getPingYin(name);
            if (name.equals("重固")) {
                pinyin = "chonggu";
            }
            jdbcTemplate.update("update  city_business_area" +
                    "        set en_name=? where id =?", pinyin, id);
        }
    }

    public void communityUpdate() {
        List<Map<String, Object>> map = jdbcTemplate.queryForList("SELECT *  from city_community");
        for (Map<String, Object> map1 : map) {
            String community_name = (String) map1.get("community_name");
            try {
                String community_first_en_name = PinyinUtils.converterToFirstSpell(community_name);
                int id = (int) map1.get("id");
                jdbcTemplate.update("update  city_community " +
                        " set community_first_en_name=? " +
                        " where id =? ", community_first_en_name, id);
            } catch (Exception ex) {
                LoggerFactory.getLogger(PinyinService.class).info("",ex);
                System.out.println(community_name);
            }

        }
    }

    public static void main(String[] args) {
        String text4 = "/map/sale/#l1=31.322207&l2=121.518914&l3=18&flag=1&commname=尚浦名邸&commid=598058";

        String qu = text4.substring(text4.indexOf("l1=") + 3, text4.indexOf("&l2"));
        String qu1 = text4.substring(text4.indexOf("l2=") + 3, text4.indexOf("&l3"));
        String qu2 = text4.substring(text4.indexOf("commid=") + 7);
        System.out.println(qu);
        System.out.println(qu1);
        System.out.println(qu2);

        System.out.println(PinyinUtils.converterToFirstSpell("我是绝地反击"));

    }

}
